package dao

import (
	"fmt"
	"github.com/jinzhu/gorm"
)

type FilterProduct struct {
	Id                 int64  `gorm:"primaryKey"`
	ProdPictureFileURL string `gorm:"column:prodPictureFileURL;type:varchar(255)"`
	Nickname           string `gorm:"column:nickname;type:varchar(255)"`
	ModelName          string `gorm:"column:modelName;type:varchar(255)"`
	ModelYear          string `gorm:"column:modelYear;type:varchar(255)"`
	ModelTypeCode      string `gorm:"column:modelTypeCode;type:varchar(255)"`
	ProductNo          string `gorm:"column:productNo;type:varchar(255)"`
	ColorType          string `gorm:"column:colorType;type:varchar(255)"`
	ColorName          string `gorm:"column:colorName;type:varchar(255)"`
	ProdPictureNo      string `gorm:"column:prodPictureNo;type:varchar(255)"`
	ReleaseYymm        string `gorm:"column:releaseYymm;type:varchar(255)"`
	ModelComment       string `gorm:"column:modelComment;type:varchar(255)"`
	ModelId            int64  `gorm:"column:modelId;type:bigint(20)"`
}

type FilterProductDao struct {
	db *gorm.DB
}

func NewFilterProductDao(db *gorm.DB) *FilterProductDao {
	return &FilterProductDao{db: db}
}

func (f *FilterProductDao) CreateFilterProduct(param *FilterProduct) int64 {
	err := f.db.Create(param).Error
	if err != nil {
		fmt.Print("写入 FilterProduct db错误", err)
	}
	return param.Id
}

func (f *FilterProductDao) GetListByModelId(modelId string) []*FilterProduct {
	res := make([]*FilterProduct, 0)
	f.db.Where("modelId = ?", modelId).Find(&res)
	return res
}
